//
//  WXPFaceScanBtn.m
//  MexicoLoan
//
//  Created by wxp on 2025/2/27.
//

#import "WXPFaceScanBtn.h"

@interface WXPFaceScanBtn ()

@end

@implementation WXPFaceScanBtn

#pragma mark - lazy
- (UIImageView *)imageFaceScan{
    if (_imageFaceScan == nil) {
        _imageFaceScan = [UIImageView new];
        _imageFaceScan.image = [UIImage imageNamed:@"icon-face-scan"];
        _imageFaceScan.contentMode = UIViewContentModeScaleToFill;
        _imageFaceScan.clipsToBounds = YES;
        _imageFaceScan.userInteractionEnabled = true;
        _imageFaceScan.widthHeight = XY(196, 196);
        UITapGestureRecognizer * tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
        [_imageFaceScan addGestureRecognizer:tapGestureRecognizer];
    }
    return _imageFaceScan;
}
-(UIButton *)btnAuth{
    if (_btnAuth == nil) {
        _btnAuth = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnAuth.backgroundColor = COLOR_PRIMARY;
        _btnAuth.titleLabel.font = [UIFont systemFontOfSize:14];
        [_btnAuth setTitle:@"Inicial el reconocimiento" forState:(UIControlStateNormal)];
        [_btnAuth setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        _btnAuth.widthHeight = XY(SCREEN_WIDTH-2*85, BUTTON_HEIGHT);
        [GlobalMethod setRoundView:_btnAuth color:[UIColor clearColor] numRound:_btnAuth.height/2 width:0];
        WEAKSELF
        [_btnAuth setNoRepeatActionWithInterval:1 action:^(UIButton * _Nonnull button) {
            [NSObject clickFeedback];
            [weakSelf.btnAuth addClickAnimate];
            if(weakSelf.blockAuth){
                weakSelf.blockAuth();
            }
        }];
    }
    return _btnAuth;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.width = SCREEN_WIDTH;
        [self configUI];
    }
    return self;
}

//添加subview
- (void)configUI{
    [self addSubview:self.imageFaceScan];
    [self addSubview:self.btnAuth];
    //初始化页面
    [self resetView];
}

#pragma mark - 手势点击
- (void)tapClick:(UITapGestureRecognizer * )tap{
    [NSObject clickFeedback];
    [tap.view addClickAnimate];
    if(self.blockAuth){
        self.blockAuth();
    }
}

#pragma mark - resetView
- (void)resetView{
    self.imageFaceScan.centerXTop = XY(SCREEN_WIDTH/2, 0);
    self.btnAuth.centerXTop = XY(SCREEN_WIDTH/2, self.imageFaceScan.bottom+Ratio(5));
    self.height = self.btnAuth.bottom;
}

@end
